package com.tuniu.agents.common.command.match;

import com.tuniu.agents.command.match.AbstractMatch;

import java.util.List;
import java.util.Map;

/**
 * This class is used for matching strings based on given parameters.
 */
public class StringMatch extends AbstractMatch {

    /**
     * The key for string matching.
     */
    public static final String KEY_STRING = "string";

    @Override
    public boolean matches(String input, Map<String, Object> params, Map<String, Object> context) {
        input = input.trim();
        Object stringValue = params.get(KEY_STRING);
        if (stringValue instanceof String) {
            return input.equals(stringValue);
        } else if (stringValue instanceof List) {
            List<String> value = (List<String>) stringValue;
            return value.contains(input);
        } else {
            return false;
        }
    }

}
